package com.mchat.communication.service.impl;

import com.mchat.common.entity.user.User;
import com.mchat.communication.exception.NotFoundException;
import com.mchat.communication.repository.UserRepository;
import com.mchat.communication.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserRepository userRepository;

    @Override
    public String getUserSeqByUserName(String userName) {
        User user = userRepository.findByUserName(userName);
        return user.getUserSeq();
    }

    @Override
    public String getUserSeqByUserId(Integer userId) throws NotFoundException {
        User user = userRepository.findById(userId).orElse(null);
        if (user == null) {
            throw new NotFoundException("User not found id:" + userId);
        }
        return user.getUserSeq();
    }

    @Override
    public User getUserBySeq(String userSeq) {
        return userRepository.findByUserSeq(userSeq);
    }
}
